#include <iostream>
#include "ConnectionPool.h"
using namespace std;

int main()
{
    /*
    // 测试单个连接
    Connection conn;
    char sql[1024]={0};
    sprintf(sql,"insert into user(name, age, sex) values('%s', '%d', '%s')", "lishan", 20, "female");
    conn.connect("172.17.0.2", 3306, "root", "root", "chat");
    conn.update(sql);
    */
    // 1000次无连接池 420000 ms 有连接池 150000 (ms)
    // 5000次无连接池 1310000 ms 有连接池 670000 (ms)
    // 10000次无连接池 2800000 ms 有连接池 1230000 (ms)

    // 压力测试 1000次
    clock_t begin = clock();
    // ConnectionPool *cp = ConnectionPool::getConnectionPool();
    for (int i = 0; i < 5000; i++)
    {
        // 无连接池
        Connection conn;
        char sql[1024] = {0};
        sprintf(sql, "insert into user(name, age, sex) values('%s', '%d', '%s')", "lishan", 20, "female");
        conn.connect("172.17.0.2", 3306, "root", "root", "chat");
        conn.update(sql);

        // 有连接池
        // shared_ptr<Connection> sp = cp->getConnection();
        // char sql[1024] = {0};
        // sprintf(sql, "insert into user(name, age, sex) values('%s', '%d', '%s')", "lishan", 20, "female");
        // sp->update(sql);
    }
    clock_t end = clock();
    cout << (end - begin) << " (ms)\n";

    return 0;
}